package me.leiusual.sharing.ui.shop.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import me.leiusual.sharing.R

/**
 * author: leiusual
 * create on: 2019-08-10
 * description:
 */
class ShopManageAdapter(
    private val clickListener: (Long) -> Unit
) : RecyclerView.Adapter<ShopManageViewHolder>() {

  private val dataSet = mutableListOf<Item>()

  override fun getItemCount(): Int {
    return dataSet.size
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShopManageViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_shop_manage, parent, false)
    return ShopManageViewHolder(itemView, clickListener)
  }

  override fun onBindViewHolder(holder: ShopManageViewHolder, position: Int) {
    holder.bind(dataSet[position])
  }

  fun submitList(map: Map<Long, String>) {
    dataSet.clear()
    map.entries.forEach {
      dataSet.add(Item(it.key, it.value))
    }
    notifyDataSetChanged()
  }

  data class Item(val storeId: Long, val storeName: String)
}